<#import "/manage/tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="等级管理">
<form id="searchForm" class="form-panel">
    <ul class="panel-content">
        <li>
            <div class="form-actions span6">
                <a href="javascript:add()" class="button button-success">
                    <i class="icon-plus-sign icon-white"></i> 添加
                </a>
                <a  class="button button-danger" onclick="return delFunction();">
                    <i class="icon-remove-sign icon-white"></i> 删除
                </a>
            </div>
        </li>
    </ul>
</form>
<div id="grid"></div>
<#------------------------------------------------------编辑表单start------------------------------------------------------->
<div id="addContent" style="display:none;">
    <form class="form-horizontal" action="${basepath}/manage/accountRank/insertJson" id="addForm" method="post">

        <div class="row">
            <div class="control-group span16">
                <label class="control-label">code：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="code" data-rule="{required : true; max:10}"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">等级名称：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="name" data-rule="{max:10}"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">最小积分：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="minScore" data-rule="{max:10}"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">最大积分：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="maxScore"data-rule="{max:10}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">备注：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="remark">
                </div>
            </div>
        </div>
    </form>
    </div>
<div id="editContent" style="display:none">
    <form class="form-horizontal" action="${basepath}/manage/accountRank/updateJson" id="editForm" method="post">
        <input type="hidden" class="input-normal control-text" name="id"/>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">code：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="code" data-rule="{required : true; max:10}"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">等级名称：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="name" data-rule="{max:10}"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">最小积分：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="minScore" data-rule="{max:10}"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">最大积分：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="maxScore"data-rule="{max:10}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">备注：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="remark">
                </div>
            </div>
        </div>
    </form>
<#------------------------------------------------------编辑表单  end-------------------------------------------------------->
</div>
<script>
    /*--------------------------------------------------表格数据渲染start----------------------------------------------------*/
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: 'code', dataIndex: 'code', width: "10%"},
                {title: '等级名称', dataIndex: 'name', width: "20%"},
                {
                    title: '积分范围', dataIndex: '', width: "50%", renderer: function (value, obj, index) {
                    return obj.minScore + "~" + obj.maxScore;
                }
                },
                {
                    title: '操作', dataIndex: 'id', width: "20%", renderer: function (value) {
                    return '<a href="javascript:edit(' + value + ')">编辑</a>';
                }
                }
            ];
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();
    var params = form.serializeToObject();
    params.length = '10';
    form.on('beforesubmit', function (ev) {
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    var store = new Store({
                url: 'loadData',
                autoLoad: true, //自动加载数据
                params: params,
                pageSize: 10,	// 配置分页数目
                root: 'list',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });
    grid.render();
    /*--------------------------------------------------表格数据渲染 end ---------------------------------------------------*/
    /*--------------------------------------------------新增表单处理start---------------------------------------------------*/
    var addForm = new BUI.Form.Form({
        srcNode: '#addForm',
        submitType : 'ajax',
        callback : function(data){
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            addDialog.close();
        }
    }).render();

    var addDialog = new BUI.Overlay.Dialog({
        title: '新增等级',
        width: 500,
        height: 320,
        contentId: 'addContent',
        success: function () {
            addForm.ajaxSubmit();
        }
    });
    //添加按钮事件
    function add() {
        addDialog.show();
    }
    /*--------------------------------------------------新增表单处理 end---------------------------------------------------*/
    /*--------------------------------------------------编辑表单处理start---------------------------------------------------*/
    var editForm = new BUI.Form.Form({
        srcNode: '#editForm',
        submitType : 'ajax',
        callback : function(data){
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            editDialog.close();
        }
    });
    editForm.render();

    var editDialog = new BUI.Overlay.Dialog({
        title: '编辑等级',
        width: 500,
        height: 320,
        contentId: 'editContent',
        success: function () {
            editForm.ajaxSubmit();
        }
    });
    //编辑按钮事件
    function edit(id) {
        $.ajax({
            type:"POST",
            dataType:"json",
            url:"${basepath}/manage/accountRank/toEditJson",
            data:{id:id},
            success:function(data) {
                var form =$("#editForm")[0];
                BUI.FormHelper.setFields(form,data.data);
                editDialog.show();
            }
        });
    }
    /*----------------------------------------------编辑表单处理 end------------------------------------*/


</script>

</@page.pageBase>